package com.miaoke;

import com.miaoke.annotation.ServiceMapped;
import com.miaoke.entity.RpcTransferDto;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class RpcInvocationHandler implements InvocationHandler {
    private Class<?> clazz;

    public RpcInvocationHandler(Class clazz) {
        this.clazz = clazz;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        RpcTransferDto dto=new RpcTransferDto();
        dto.setClassName(clazz.getDeclaredAnnotation(ServiceMapped.class).mapped());
        dto.setMethodName(method.getName());
        dto.setParams(args);
        return ClientSocket.callRemoteService(dto,"localhost",6666);
    }
}
